package com.fading.mall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.fading.mall.product.entity.AttrEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.fading.mall.product.entity.AttrGroupEntity;
import com.fading.mall.product.service.AttrGroupService;
import com.fading.common.utils.PageUtils;
import com.fading.common.utils.R;



/**
 * 属性分组
 *
 * @author fadingYY
 * @email 2714592747@qq.com
 * @date 2021-08-11 16:21:42
 */
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list/{cateLogId}")
    public R list(@RequestParam Map<String, Object> params,
                  @PathVariable Long cateLogId){
//        PageUtils page = attrGroupService.queryPage(params);
        PageUtils page = attrGroupService.queryPage(params,cateLogId);

        return R.ok().put("page", page);
    }


    @RequestMapping("/{attrgroupId}/attr/relation")
    public R getAttrDetails(@PathVariable("attrgroupId") Long attrgroupId){
        List<AttrEntity> attrList = attrGroupService.getAttrs(attrgroupId);

        return R.ok().put("data", attrList);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrGroupId}")
    public R info(@PathVariable("attrGroupId") Long attrGroupId){
		AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);


        return R.ok().put("attrGroup", attrGroup);
    }

    @DeleteMapping("/attr/relation/delete")
    public R deletetRelation(@PathVariable("attrGroupId") Long attrGroupId){
        AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);


        return R.ok().put("attrGroup", attrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.save(attrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrGroupEntity attrGroup){
		attrGroupService.updateById(attrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrGroupIds){
		attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

        return R.ok();
    }

}
